<Selector x:Class="Ricciolo.Controls.Selector3D"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


  <Selector.Template>

    <ControlTemplate>
		  
      <Grid x:Name="panel" Background="{TemplateBinding Background}">
        <Grid.Resources>
          <Storyboard x:Key="RotationEffectNext">
            <Point3DAnimation Duration="0:0:1.5" From="0,0,2" To="0,0,2.5" DecelerationRatio="0.7" Storyboard.TargetName="camera" Storyboard.TargetProperty="Position" />
            <DoubleAnimation BeginTime="0:0:0.2" By="-90" Duration="0:0:5" DecelerationRatio="0.7" Storyboard.TargetName="rotation" Storyboard.TargetProperty="Angle" />
            <Point3DAnimation BeginTime="0:0:1.2" Duration="0:0:1.5" To="0,0,2" AccelerationRatio="0.7" From="0,0,2.5" Storyboard.TargetName="camera" Storyboard.TargetProperty="Position" />
          </Storyboard>
          <Storyboard x:Key="RotationEffectBack">
            <Point3DAnimation Duration="0:0:0.5" From="0,0,2" To="0,0,2.5" DecelerationRatio="0.7" Storyboard.TargetName="camera" Storyboard.TargetProperty="Position" />
            <DoubleAnimation BeginTime="0:0:0.2" By="90" Duration="0:0:5" DecelerationRatio="0.7" Storyboard.TargetName="rotation" Storyboard.TargetProperty="Angle" />
            <Point3DAnimation  BeginTime="0:0:1.2" Duration="0:0:0.5" To="0,0,2" AccelerationRatio="0.7" From="0,0,2.5" Storyboard.TargetName="camera" Storyboard.TargetProperty="Position" />
          </Storyboard>
		  <Storyboard x:Key="RotationEffectStart">
			<Point3DAnimation Duration="0:0:1.5" From="0,0,2" To="0,0,2.5" DecelerationRatio="0.7" Storyboard.TargetName="camera" Storyboard.TargetProperty="Position" />
			<DoubleAnimation BeginTime="0:0:0.2" By="-30"  Duration="0:0:5" DecelerationRatio="0.7" Storyboard.TargetName="rotation" Storyboard.TargetProperty="Angle" />
			<Point3DAnimation  BeginTime="0:0:1.2" Duration="0:0:1.5" To="0,0,2" AccelerationRatio="0.7" From="0,0,2.5" Storyboard.TargetName="camera" Storyboard.TargetProperty="Position" />
		  </Storyboard>
        </Grid.Resources>


        <Viewbox Stretch="Fill">
			<Viewport3D x:Name="viewPort3D" Width="500" Height="500">
              <Viewport3D.Camera>
                <PerspectiveCamera x:Name="camera" FarPlaneDistance="10" LookDirection="0,0,-1" UpDirection="0,1,0" NearPlaneDistance="0" Position="0,0,2" FieldOfView="37" />
              </Viewport3D.Camera>

              <ModelVisual3D>
                <ModelVisual3D.Transform>					
						<RotateTransform3D>
                    <RotateTransform3D.Rotation>
                      <AxisAngleRotation3D x:Name="rotation" Axis="0,1,0" Angle="0" />
                    </RotateTransform3D.Rotation>
                  </RotateTransform3D>
                </ModelVisual3D.Transform>
                <ModelVisual3D.Content>
                  
                  
                  <Model3DGroup>

                    <AmbientLight Color="#FFFFFF" />
                    <DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
                    <DirectionalLight Color="#FFFFFF" Direction="0.612372,-0.5,-0.612372" />
                    <Model3DGroup x:Name="cube">

                      <GeometryModel3D>
                        <GeometryModel3D.Material>
                          <MaterialGroup>
                          </MaterialGroup>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.Geometry>
                          <MeshGeometry3D
                            TextureCoordinates="1 1  1 0  0 0  0 1"
                            TriangleIndices="0,1,2 2,3,0 4,5,6 6,7,4"
                            Normals="1,0,0 1,0,0 1,0,0 1,0,0"
                            Positions="0.5,-0.5,-0.5 0.5,0.5,-0.5 0.5,0.5,0.5 0.5,-0.5,0.5 "
								/>
                        </GeometryModel3D.Geometry>
                      </GeometryModel3D>


                      <GeometryModel3D>
                        <GeometryModel3D.Material>
                          <MaterialGroup>
                          </MaterialGroup>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.Geometry>
                          <MeshGeometry3D
                            TextureCoordinates="1 1  1 0  0 0  0 1"
                            TriangleIndices="0,1,2 2,3,0 4,5,6 6,7,4"
                            Normals="0,0,-1 0,0,-1 0,0,-1 0,0,-1"
                            Positions="-0.5,-0.5,-0.5 -0.5,0.5,-0.5 0.5,0.5,-0.5 0.5,-0.5,-0.5" />
                        </GeometryModel3D.Geometry>
                      </GeometryModel3D>


                      <GeometryModel3D>
                        <GeometryModel3D.Material>
                          <MaterialGroup>
                          </MaterialGroup>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.Geometry>
                          <MeshGeometry3D
                            TextureCoordinates="0 0  0 1  1 1  1 0"
                            TriangleIndices="0,1,2 2,3,0 4,5,6 6,7,4"
                            Normals="-1,0,0 -1,0,0 -1,0,0 -1,0,0 "
                            Positions="-0.5,0.5,-0.5 -0.5,-0.5,-0.5 -0.5,-0.5,0.5 -0.5,0.5,0.5 "
								/>
                        </GeometryModel3D.Geometry>
                      </GeometryModel3D>

                      <GeometryModel3D>
                        <GeometryModel3D.Material>
                          <MaterialGroup>
                          </MaterialGroup>
                        </GeometryModel3D.Material>
                        <GeometryModel3D.Geometry>
                          <MeshGeometry3D
                            TextureCoordinates="0 1  1 1  1 0  0 0"
                            TriangleIndices="0,1,2 2,3,0 4,5,6 6,7,4"
                            Normals="0,0,1 0,0,1 0,0,1 0,0,1 "
                            Positions="-0.5,-0.5,0.5 0.5,-0.5,0.5 0.5,0.5,0.5 -0.5,0.5,0.5"
								/>
                        </GeometryModel3D.Geometry>
                      </GeometryModel3D>

                    </Model3DGroup>
                  </Model3DGroup>
                </ModelVisual3D.Content>
              </ModelVisual3D>
            </Viewport3D>
		</Viewbox>

         <ItemsPresenter x:Name="presenter" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
      </Grid>
    </ControlTemplate>
  </Selector.Template>
</Selector>
